	
	package servlet.user;
	
	import java.io.IOException;
	import java.util.ArrayList;
	import java.util.List;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.http.HttpSession;
	
	import enitys.User;
	
	import service.UserManager;
	
	public class FindAllInfo extends HttpServlet {
	
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
	
		/**
		 * Constructor of the object.
		 */
		public FindAllInfo() {
			super();
		}
	
		/**
		 * The doGet method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to get.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
				doPost(request,response);
		}
	
		/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			HttpSession session = request.getSession();
			int ID = Integer.parseInt(session.getAttribute("shenfen").toString());
			int id = Integer.parseInt(session.getAttribute("id").toString());
			//获取业务对象，调用业务方法完成业务
			UserManager manager = UserManager.getInstance();
			List<User> user = new ArrayList<User>();
			//System.println("");
			//根据身份 转发到相应的页面
			if(ID == 1){//管理员查看所有信息
				user =manager.find();
				request.setAttribute("user", user);
				this.getServletConfig().getServletContext().getRequestDispatcher("/jsp/user_info/s_mananger.jsp").forward(request, response);
			}
			if(ID==0){//用户查看自己的信息
			  User user1= manager.getUserById(id);
				request.setAttribute("user", user1);
				this.getServletConfig().getServletContext().getRequestDispatcher("/jsp/user_info/s_info.jsp").forward(request, response);
			}
			
			
		}
	}
